package com.hongshan.wallet.core.home

import android.arch.lifecycle.ViewModelProviders
import android.databinding.ObservableField
import android.databinding.ViewDataBinding
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.hongshan.wallet.BR
import com.hongshan.wallet.R
import com.hongshan.wallet.base.BaseOnPropertyChangedCallback
import com.hongshan.wallet.base.MyActivity
import com.hongshan.wallet.bean.PaymentMethod
import com.hongshan.wallet.router.RouterIndex
import kotlinx.android.synthetic.main.activity_pay_method.*
import kotlinx.android.synthetic.main.appbar.*

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.home
 * @author   : zhangxx
 * @date     : 2019/3/27
 * @email    : qq957413212@hotmail.com
 * @desc     : //TUDO
 */

@Route(path = RouterIndex.PAY_METHOD)
class PayMethodActivity : MyActivity<ViewDataBinding, PayMethodViewModel>() {

//    private val gridLayoutManager by lazy { (rvPayMethod.layoutManager as GridLayoutManager) }

    override fun initVariableId() = BR.topUpVm

    override fun initContentView(savedInstanceState: Bundle?) = R.layout.activity_pay_method

    override fun initViewModel() = ViewModelProviders.of(this)[PayMethodViewModel::class.java]

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        tvTitle.text = "充值"
//        gridLayoutManager.spanCount = 1
        viewModel.payment_method.addOnPropertyChangedCallback(BaseOnPropertyChangedCallback<ObservableField<List<PaymentMethod>>> { sender, _ ->
            val payMethods = sender.get()
            if (payMethods != null) {
                rvPayMethod.adapter = PayMethodAdapter(payMethods, this)
//                gridLayoutManager.spanSizeLookup = PayMethodSpanSizeLookup(payMethods)
            }
        })
        viewModel.getTopUpInfo()
    }
}